﻿<cfcomponent displayname="Setting" hint="Setting" extends="Model" output="false">

	<cffunction name="init" access="public" hint="init" displayname="init">
		
		<cfscript>
			
			return this;
			
		</cfscript>
		
	</cffunction>
	
	<cffunction name="getSetting" access="public" hint="get setting" displayname="getSetting" description="get setting from database"> 
		
		<cfargument name="key" hint="key" displayname="key" required="true" type="string"> 
		
		<cfscript>
			
			setting = this.findOne(select="settingvalue", where="settingname='#arguments.key#'");
			
			if (isObject(setting)) {
				return setting.settingvalue;
			}
			
			return false;
			
		</cfscript>
		
	</cffunction>
	
	<cffunction name="setSetting" access="public" hint="set setting" displayname="set setting" description="set setting to database">
		
		<cfargument name="key" hint="key" displayname="key" required="true" type="string">
		<cfargument name="value" hint="value" displayname="value" required="true" type="string">
		
		<cfscript>
			
			setting = this.findOne(where="settingname='#arguments.key#'");
			
			if (IsObject(setting)) {
				setting.settingvalue = arguments.value;
			
				setting.save();
			}
			
			return false;			
			
		</cfscript>
		
	</cffunction> 
	
</cfcomponent>